<%@ page import="com.situ.web.util.PageInfo" %>
<%@ page import="com.situ.web.pojo.Course" %><%--
  Created by IntelliJ IDEA.
  User: Gao
  Date: 2023/7/28
  Time: 9:57
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
    <link rel="stylesheet" href="static/bootstrap-3.4.1-dist/css/bootstrap.css">
</head>
<body>
    <%
        PageInfo<Course> pageInfo = (PageInfo<Course>) request.getAttribute("pageInfo");
    %>
    <a class="btn btn-primary" href="<%=request.getContextPath()%>/course_add.jsp">添加</a>
    <table class="table table-striped table-bordered table-hover table-condensed">
        <tr>
            <td>ID</td>
            <td>名字</td>
            <td>学分</td>
            <td>编辑</td>
            <td>删除</td>
        </tr>
        <%
            for (Course course : pageInfo.getList()) {
        %>
        <tr>
            <td><%=course.getId()%></td>
            <td><%=course.getName()%></td>
            <td><%=course.getCredit()%></td>
            <td><a href="<%=request.getContextPath()%>/course?method=getCourseUpdatePage&id=<%=course.getId()%>">编辑</a></td>
            <td><a href="javascript:deleteById(<%=course.getId()%>)">删除</a></td>
        </tr>
        <%
            }
        %>
    </table>

    <nav aria-label="Page navigation">
        <ul class="pagination">
            <%
                if (pageInfo.getPageNo() == 1) {
            %>
                    <li class="disabled">
                        <a href="#" aria-label="Previous">
                            <span aria-hidden="true">&laquo;</span>
                        </a>
                    </li>
            <%
                } else {
            %>
                    <li>
                        <a href="<%=request.getContextPath()%>/course?method=selectByPage&pageNo=<%=pageInfo.getPageNo()-1%>" aria-label="Previous">
                            <span aria-hidden="true">&laquo;</span>
                        </a>
                    </li>
            <%
                }
            %>

            <%
                for (int i = 1; i <= pageInfo.getTotalPage(); i++) {
                    if (i == pageInfo.getPageNo()) {
            %>
                        <li class="active"><a href="#"><%=i%></a></li>
            <%
                    } else {
            %>
                         <li><a href="<%=request.getContextPath()%>/course?method=selectByPage&pageNo=<%=i%>"><%=i%></a></li>
            <%
                    }
                }
            %>
            <li>
                <a href="<%=request.getContextPath()%>/course?method=selectByPage&pageNo=<%=pageInfo.getPageNo()+1%>" aria-label="Next">
                    <span aria-hidden="true">&raquo;</span>
                </a>
            </li>
        </ul>
    </nav>

    <script>
        function deleteById(id) {
            var isDelete = confirm('您确认要删除？');
            if (isDelete) {
                location.href = '<%=request.getContextPath()%>/course?method=deleteById&id=' + id;
            }
        }
    </script>
</body>
</html>
